package com.ruoyi.ai.controller;

import com.ruoyi.chatgpt.domain.GptMessage;
import com.ruoyi.chatgpt.service.IGptMessageService;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * @description:MessageController
 * @author: caoes
 * create:2023/7/1 15:35
 **/
@Api(tags = "消息相关接口")
@RestController
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private IGptMessageService gptMessageService;

    @ApiOperation(value = "queryMessageHistory", notes = "查询聊天历史消息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "chatId", value = "聊天室ID", required = true, dataType = "Long", example = "0")
    })
    @GetMapping(value = "history")
    public AjaxResult queryMessageHistory(Long chatId) {
        // 参数校验
        if (Objects.isNull(chatId)) {
            return AjaxResult.error("对话不能为空");
        }
        GptMessage gptMessage = new GptMessage();
        gptMessage.setChatId(chatId);
        List<GptMessage> gptMessageList = gptMessageService.selectGptMessageList(gptMessage);
        return AjaxResult.success(gptMessageList);
    }
}
